package edu.bu.manateem.msg.heatmap;


public class FireColorMap 
{
	float[] _rmap;
	float[] _gmap;
	float[] _bmap;

	float[][] out;
	
	public FireColorMap()
	{
		_rmap   = new float[] {1,    1, 1, 1}; //red
		_gmap = new float[] {0, 0.5f, 1, 1}; //green
		_bmap  = new float[] {0,    0, 0, 1}; //blue

	}

	private float[] remap(float[] x, float[] out, float[] y, float range)
	{
		out = Spectrum.realloc(out, x.length);
		float z, dz;
		for (int i = 0; i < x.length; i++)
		{
			z = x[i] / range * ((float)(y.length - 1));
			int b = (int)(z);
			if (b > y.length - 2) b = y.length - 2;
			if (b < 0) b = 0;
			dz = Math.max(Math.min(z - (float)b, 1), 0);
			out[i] = range * ((1 - dz) * y[b] + dz * y[b + 1]);
		}
		return out;
	}


	public float[][] remap(float[] x, float max)
	{
		if (null == out)
			out = new float[3][x.length];
		out[0] = remap(x, out[0], _rmap, max);
		out[1] = remap(x, out[1], _gmap, max);
		out[2] = remap(x, out[2], _bmap, max);
		return out;
	}

}


